package com.vue.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vue.pojo.CateGory;
import com.vue.service.CateGoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CateGoryController {

    @Autowired
    private CateGoryService cateGoryService;

    @RequestMapping("/show")
    public ResponseEntity<Page<CateGory>> show(Integer pagenumber, Integer pagesize) {
        Page<CateGory> findll = cateGoryService.findll(pagenumber, pagesize);
        return new ResponseEntity<>(findll, HttpStatus.OK);
    }

    @RequestMapping("/add")
    public ResponseEntity<String> add(String name, String level, String upperID) {
        CateGory cateGory = new CateGory();
        cateGory.setLevel(Integer.parseInt(level));
        cateGory.setName(name);
        cateGory.setUpperID(Integer.parseInt(upperID));
        int i = cateGoryService.adllOne(cateGory);
        if(i==1){
            return new ResponseEntity<>("添加成功",HttpStatus.OK);
        }else{
            return new ResponseEntity<>("添加失败",HttpStatus.OK);
        }
    }
    @RequestMapping("/del")
    public ResponseEntity<String> del(Integer id){
        int i = cateGoryService.delOne(id);
        if(i==1){
            return new ResponseEntity<>("删除成功",HttpStatus.OK);
        }else{
            return new ResponseEntity<>("删除失败",HttpStatus.OK);
        }
    }
}
